<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>"
	type="text/javascript"></script>
<!-- validate -->
<link rel="stylesheet"
	href="<c:url value='/static/themes/bootstrap/bootstrapValidator.min.css'/>" />
<script type="text/javascript"
	src="<c:url value='/static/themes/bootstrap/bootstrapValidator.min.js'/>"></script>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set>
<title>管理员人工划款页面</title>
</head>
<body>
	<div class="col-lg-12">
		<div id="message"></div>
		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<form class="form-horizontal" id="searchForm">
					<div class="row">
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">生账ID：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="userId"
									name="userId" placeholder="生账ID">
							</div>
						</div>
						<div class="form-group col-sm-4">
							<label class="col-sm-4 control-label">账号类型：</label>
							<div class="col-sm-8">
								<select id="userType" name="userType" class="form-control">
									<option value="1">买手生财账户</option>
									<option value="2">商家基本账户</option>
								</select>
							</div>
						</div>
						<div class="form-group col-sm-1"></div>
						<div class="form-group col-sm-3">
							<button type="button" id="searchButton"
								class="btn btn-primary glyphicon glyphicon-search">查询</button>
						</div>

					</div>
				</form>
			</div>
			<div class="panel-body">
				<form class="form-horizontal" id="sectionForm">
					<div class="row">
						<h4 style="padding-left: 40px; padding-bottom: 10px">
							你即将对生财ID：<span style="color: #FFB253;" id="userId_show">${task.businessUserId }</span><span
								id="userType_show"></span>生财账户进行资金调整
						</h4>
					</div>
					<input type="hidden" id="userId_hidden" name="userId"> <input
						type="hidden" id="userType_hidden" name="userType">
					<div class="row">
						<div class="form-group col-sm-6">
							<label class="col-sm-4 control-label">请输入调整金额：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="amount"
									name="amount" placeholder="调整金额">
							</div>
						</div>
						<div class="form-group col-sm-6">
							<label class="col-sm-4 control-label">请选择收支类型：</label>
							<div class="col-sm-8">
								<select id="paymentsDirection" name="paymentsDirection"
									class="form-control">
									<option value="1">增加</option>
									<option value="0">扣除</option>
								</select>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="form-group col-sm-6">
							<label class="col-sm-4 control-label">相关订单ID：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="orderId"
									name="orderId" placeholder="相关订单ID">
							</div>
						</div>
						<div class="form-group col-sm-6">
							<label class="col-sm-4 control-label">任务ID：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="taskId"
									name="taskId" placeholder="任务ID">
							</div>
						</div>
					</div>
					<div class="row">
						<div class="form-group col-sm-12">
							<label class="col-sm-2 control-label">调整原因：</label>
							<div class="col-sm-10">
								<textarea id="opinion" class="form-control " name="opinion"
									data-plugin-markdown-editor rows="10"></textarea>

							</div>
						</div>
					</div>
					<div class="row" style="padding-top: 30px">
						<div class="form-group col-sm-12  text-center">
							<button type="button" id="submit" class="btn btn-warning btn-sm"
								style="width: 150px;">提交</button>
						</div>
					</div>
				</form>

			</div>

		</div>
	</div>
	<script type="text/javascript">
		var path = '${path}';
		$(function($) {
			$('#sectionForm').hide();

			$('#searchButton').click(function() {
				$('#searchForm').bootstrapValidator('validate');
			});

			$('#submit').click(function() {
				$('#sectionForm').bootstrapValidator('validate');
			});

			$('#searchForm').bootstrapValidator({
				message : '这个值未通过验证',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					userId : {
						validators : {
							notEmpty : {
								message : '生账ID是必须的不能为空'
							},
						}
					}
				}
			}).on('success.form.bv', function(e) {
				//查询
				$.ajax({
					type : "post",
					url : path + "/capital/getUserInfo",
					cache : false,
					data : {
						userId : $('#userId').val(),
						userType : $('#userType').val(),
						_t : new Date().getTime()
					},
					dataType : "json",
					success : function(data) {
						showmessage(data.msg);
						if (data.success) {
							var id = data.retObj.id;
							var type = data.retObj.type;
							$('#userId_hidden').val(id);
							$('#userType_hidden').val(type);
							$('#userId_show').html(id);
							$('#userType_show').html(type == 1 ? '买手' : '商家');
							$('#sectionForm')[0].reset(); 
							$('#sectionForm').show();
						} else {
							$('#sectionForm').hide();
						}
					}
				});
			});

			$('#sectionForm').bootstrapValidator({
				message : '这个值未通过验证',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					amount : {
						validators : {
							notEmpty : {
								message : '金额是必须的不能为空'
							},
							regexp : {
								regexp : /^(([1-9]\d{0,9})|0)(\.\d{1,2})?$/,
								message : '请输入数字，最多2位小数'
							}
						}
					},
					paymentsDirection : {
						validators : {
							notEmpty : {
								message : '收支类型是必须的不能为空'
							}
						}
					},
					orderId : {
						validators : {
							notEmpty : {
								message : '相关订单ID是必须的不能为空'
							}
						}
					},
					taskId : {
						validators : {
							notEmpty : {
								message : '任务ID是必须的不能为空'
							}
						}
					},
					opinion : {
						validators : {
							notEmpty : {
								message : '调整原因是必须的不能为空'
							},
							stringLength: {
		                        max: 500,
		                        message: '调整原因长度在1-500位'
		                    }
						}
					}

				}
			}).on('success.form.bv', function(e) {
				$.blockUI({ message: '加载中...' });
				$.ajax({
					type : "post",
					url : path + "/capital/doCrossSection",
					cache : false,
					data : $('#sectionForm').serialize(),
					dataType : "json",
					success : function(data) {

						if (data.success) {
							showmessage(data.msg, function() {
								$.unblockUI();
								window.location.reload();
							});
						} else {
							$.unblockUI();
							showmessage(data.msg);
						}
					}
				});
			});

		});

		//显示消息
		function showmessage(msg, callback) {
			$('#message').ucMessage({
				msg : msg,
				callback : callback
			});
		}
	</script>
</body>
</html>